package wang.aweb.childcar.controller.management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wang.aweb.childcar.common.ApiRestResponse;
import wang.aweb.childcar.exception.CarException;
import wang.aweb.childcar.exception.CarExceptionEnum;
import wang.aweb.childcar.model.pojo.System;
import wang.aweb.childcar.service.SystemInfoService;

import java.util.Map;

@RestController
@RequestMapping("/management/set/")
public class SetController {
    @Autowired
    private SystemInfoService systemInfoService;
    @GetMapping("getInfo")
    public ApiRestResponse getInfo(){
        Map system=systemInfoService.getInfo();
        return ApiRestResponse.success(system);
    }
    @PostMapping("donate")
    public ApiRestResponse donate(@RequestBody Map<String,Object> reqMap){
        if(reqMap.get("donate_enable")==null){
            throw new CarException(CarExceptionEnum.UPDATE_FAILED);
        }
        if(reqMap.get("donate_money")==null){
            throw new CarException(CarExceptionEnum.UPDATE_FAILED);
        }
        Boolean donateEnable=(Boolean) reqMap.get("donate_enable");
        Integer donateMoney=(Integer) reqMap.get("donate_money");
        systemInfoService.update(donateEnable,donateMoney);
        return ApiRestResponse.success();
    }

}
